package org.duang.proxy;

import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.duang.aop.Proxy;
import org.duang.config.Config;
import org.duang.ioc.Lock;
import org.duang.ioc.Mq;
import org.duang.ioc.Tx;
import org.duang.kit.ToolsKit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 框架代理类设置
 * @author laotang
 */
public class MvcProxy {
	
	private static final Logger logger = LoggerFactory.getLogger(MvcProxy.class);
	
	private static Map<Class<? extends Annotation>,Class<? extends Proxy>> annotAtionMap = new HashMap<Class<? extends Annotation>,Class<? extends Proxy>>();
	
	public MvcProxy(){
//		if(ToolsKit.isNotEmpty(Config.getZKSyncLockHost())){
//			annotAtionMap.put(Lock.class, LockProxy.class);
//		}
//		if(ToolsKit.isNotEmpty(Config.getMysqlHost()) &&  ToolsKit.isNotEmpty(Config.getMysqlPort())){
//			annotAtionMap.put(Tx.class, TxProxy.class);
//		}
//		if(ToolsKit.isNotEmpty(Config.getZKSyncLockHost())){
//			annotAtionMap.put(Mq.class, MqProxy.class);
//		}
		annotAtionMap.put(Lock.class, LockProxy.class);
		annotAtionMap.put(Tx.class, TxProxy.class);
		annotAtionMap.put(Mq.class, MqProxy.class);
	}
	
	public MvcProxy(Map<Class<?>,Class<?>> proxyMap){
		proxyMap.putAll(proxyMap);
	}
	
	public Map<Class<? extends Annotation>,Class<? extends Proxy>> getAnnotAtionMap(){
//		for(Iterator<Entry<Class<? extends Annotation>, Class<? extends Proxy>>> it = annotAtionMap.entrySet().iterator(); it.hasNext();){
//			Entry<Class<? extends Annotation>, Class<? extends Proxy>> entry = it.next();
//			logger.warn(entry.getKey()+"          "+entry.getValue());
//		}
		return annotAtionMap;
	}
}
